/*
 * Copyright 2011 Andy Lee.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package uk.co.optimisticpanda.remoteweb.command.xml

import static org.junit.Assert.*
import junit.framework.TestCase
import uk.co.optimisticpanda.remoteweb.command.CommandSet;
import uk.co.optimisticpanda.remoteweb.main.SampleWebDriverCommands


public class CommandXmlMarshallerTest extends TestCase{


	public void testMarshalUnmarshal() throws Exception {
		def marshaller = new CommandXmlMarshaller()
		def unmarshaller = new CommandXmlUnmarshaller()
		
		def writer = new StringWriter();
		def commands = new SampleWebDriverCommands().getCommandSet()

		marshaller.marshal(writer, commands)
		
		String marshal1 = writer.toString()
		println marshal1
		
		def umarshalledCommands = unmarshaller.unmarshal( writer.toString())

		writer = new StringWriter();
		marshaller.marshal(writer, umarshalledCommands)
		String marshal2 = writer.toString()
		println marshal2

		assertEquals( marshal1,marshal2)
		assertTrue( commands instanceof CommandSet)
		assertTrue( umarshalledCommands instanceof CommandSet)
		assertEquals(commands.toString(),umarshalledCommands.toString())
		assertEquals(commands,umarshalledCommands)
		
		def umarshalledCommands2 = unmarshaller.unmarshal( marshal2)
		assertEquals(commands,umarshalledCommands2)
	}
}